﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<QianBuo.Lottery.Web.Models.User.ChildsModel>" %>
<%@ Import Namespace="Code.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	会员管理
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div>
        <% Html.BeginForm(); %>
            <table class="table" width="100%">
                <tr class="th">
                    <th colspan="4" align="left">&nbsp;&nbsp;搜索条件</th>
                </tr>
                <tr>
                    <td>
                        <%=Html.LabelFor(p => p.Where.ChildName)%>
                        <%= Html.TextBoxFor(p => p.Where.ChildName, new { @class = "text100" })%>
                    </td>
                    <td>
                        <%=Html.LabelFor(p => p.Where.StartTime)%>：从
                        <%=Html.TextBoxFor(p =>p.Where.StartTime, new { @class = "text100", onClick = "WdatePicker()" })%>
                        <%=Html.ValidationMessageFor(p=>p.Where.StartTime) %>
                    </td>
                    <td>
                        到
                        <%= Html.TextBoxFor(p => p.Where.EndTime, new { @class = "text100", onClick = "WdatePicker()" })%>
                        <%=Html.ValidationMessageFor(p=>p.Where.EndTime) %>
                    </td>
                    <td rowspan='2'>
                        <input type="submit" value="查找" />
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        <%=Html.LabelFor(p => p.Where.MinMoney)%>：从
                        <%=Html.TextBoxFor(p => p.Where.MinMoney, new { @class = "text100" })%>
                        <%=Html.ValidationMessageFor(p=>p.Where.MinMoney) %>
                    </td>
                    <td>
                        到
                        <%=Html.TextBoxFor(p => p.Where.MaxMoney, new { @class = "text100" })%>
                        <%=Html.ValidationMessageFor(p=>p.Where.MaxMoney) %>
                    </td>
                </tr>
            </table>
        <% Html.EndForm(); %>
    </div>
    <div>
        <table class="table Childs_table" width="100%">
            <% if (Model.MyChilds != null){ %>
            <tr>
                <td colspan='6' align="left">
                    <%
                        var user = Model.MyChilds.Where(p => p.Uid == Model.LoginUserID).FirstOrDefault();
                        while (user != null)
                        {
                            if (Model.CurrentUid == user.Uid) 
                            {
                                %>
                                <%=Html.ActionLink(string.Format("{0}({1})",user.LoginName,Model.ChildsCount), "Childs", new { CurrentUid = user.Uid })%>→
                                <%
                            }
                            else
                            {
                                %>
                                <%=Html.ActionLink(user.LoginName, "Childs", new { CurrentUid = user.Uid })%>→
                                <%
                            }
                            user = Model.MyChilds.Where(p => p.CommandID == user.Uid).FirstOrDefault();
                        }    
                    %>
                </td>
            </tr>
            <%} %>
            <tr class="th">
                <th>用户名</th><th>类型</th><th style=" width:50px;">余额</th><th>注册时间</th><th>最后登录时间</th><th>操作</th>
            </tr>
            <% var i = 0; foreach (var item in Model.Childs)
	        {%>
                <tr <%=i++%2==1?"class='supersede'":"" %>>
                    <td><label class="lbl"><%= item.Type == (short)UserType.Surrogate ? Html.ActionLink(item.ChildName, "Childs", new { CurrentUid = item.Uid }, new { @class="a_blue"}) : Html.Label(item.ChildName)%></label></td>
                    <td id="td_<%=i %>"><%=Html.Label(((UserType)item.Type).GetName()) %></td>
                    <td><%=item.Balance.ToString("F2") %></td>
                    <td><%=Html.Label(item.RegistTime.ToString("yyyy-MM-dd HH:mm:ss")) %></td>
                    <td><%=Html.Label(item.LastLoginTime.HasValue?item.LastLoginTime.Value.ToString("yyyy-MM-dd HH:mm:ss"):"") %></td>
                    <td>
                        <%=item.Type == (short)UserType.Member ? null : Html.ActionLink("团队 ", "AccountReport", Url.Route(new { uid = item.Uid, returnUrl =Request.RawUrl, page = Model.PageInfo.CurrPage }, new { act = "Childs", cont = "Surrogate" }),Url.Route(new {@class="a_blue"}))%>
                        &nbsp;<%=Model.CurrentUid == Model.LoginUserID ? Html.ActionLink("返奖设置 ", "PlayTypeOption", new { uid = item.Uid, returnUrl = Url.Action("Childs", new { uid = Model.CurrentUid }), page = Model.PageInfo.CurrPage }, new { @class = "a_blue" }) : MvcHtmlString.Empty%>
                      
                        &nbsp;<%=Html.ActionLink("查看返奖 ", "WinMoney", "User", Url.Route(new { uid = item.Uid, returnUrl = Url.Action("Childs", new { page = Model.PageInfo.CurrPage, uid = Model.CurrentUid }) }, new { act = "Childs", cont = "Surrogate" }), Url.Route(new {@class="a_blue"}))%>
                        &nbsp;
                        <% if (Model.CurrentUid == Model.LoginUserID){ %>
                            <label id="lblUpUser_<%=i %>" onclick="UpUser(<%=i %>,'<%=item.Uid %>')" class="link" <%=item.Type==(short)UserType.Member?"":"style='display:none;'" %>>升级为代理</label>
                        <%} %>
                    </td>
                </tr>
            <%
	        } %>
            <tr>
                <%if (Request["returnUrl"] != null)
                  { %>
                <td align="left"><a href="<%=Request["returnUrl"] %>" class="a_blue">返回>></a></td>
                <%} %>
                <td colspan='6' align="center">
                    <%=Html.Pager(Model.PageInfo.CurrPage, Model.PageInfo.PageCount, Model.PageInfo.SunCount, "PageInfo.CurrPage", Url.Route(new { Model.CurrentUid,Model.Where }), "PageInfo.PageCount")%>
                </td>
            </tr>
        </table>
    </div>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="StyleAndScript" runat="server">
<script type="text/javascript">
    function UpUser(index,id) {
        if (confirm('您确定要升级当前会员为代理吗？')) {
            getJSON('<%=Url.Action("UpUser","Surrogate") %>', { id: id }, function (result) {
                if (result.count > 0) {
                    $('.Childs_table #td_' + index).text('代理');
                    $('#lblUpUser_' + index).hide();
                    alert('操作成功！');
                }
                if (result.msg.length) {
                    alert(result.msg);
                }
            });
        }
    }
</script>
</asp:Content>
